package cn.tuling.simplefactory;

public class SimpleFactoryTest {
    public static void main(String[] args) {
        Product procut = SimpleFactory.createProcut(Product.PRODUCT_A);
        procut.show();

        Product procut1 = SimpleFactory.createProcut(Product.PRODUCT_B);
        procut1.show();
    }
}

interface Product {
    int PRODUCT_A = 0;
    int PRODUCT_B = 1;

    void show();
}

class ConcreateProductA implements Product {

    @Override
    public void show() {
        System.out.println("产品A被创建");
    }
}

class ConcreateProductB implements Product {

    @Override
    public void show() {
        System.out.println("产品B被创建");
    }
}

class SimpleFactory {
    public static Product createProcut(int type) {
        if (type == Product.PRODUCT_A) {
            return new ConcreateProductA();
        } else if (type == Product.PRODUCT_B) {
            return new ConcreateProductB();
        }
        return null;
    }
}


